package org.speed.mybatis;

import java.sql.Statement;

import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

@Intercepts({
		@Signature(type= Executor.class,method = "update",args = {MappedStatement.class,Object.class}),
		@Signature(type= Executor.class,method = "query",args = {MappedStatement.class,Object.class,RowBounds.class,ResultHandler.class}),
		@Signature(type= ResultSetHandler.class,method = "handleResultSets",args = {Statement.class}),

})
public class MyIntecepter implements Interceptor {

	@Override
	public Object intercept(Invocation invocation) throws Throwable {
		
		String target = invocation.getTarget().getClass().getName();
		String method = invocation.getMethod().getName();
		Object[] args = invocation.getArgs();
		
		
		System.out.println("target=" +  target + ",method=" + method + ",args=" + args.toString());
		
		Object result = invocation.proceed();
		
		return result;
	}

}
